/*
 * Ethan Levine
 * 
 * The contents of this file are subject to the GNU General Public
 * License (GPL) v2.  The full contents of this license can be
 * found at Mathma's website, http://www.codeplex.com/mathma/license
 */

package mathma.core.real.form;

import mathma.core.expr.Variable;
import mathma.core.expr.Expression;
import mathma.core.real.Real;
import mathma.core.expr.VariableMapping;

import mathma.core.form.BinaryExpression;
import mathma.core.form.UnknownSuspensionException;

/**
 * @since 0.1.5
 * @author Ethan Levine
 */
public class SubtractionExpression extends BinaryExpression<Real, Real> {

    public SubtractionExpression(Expression<Real> firstOperand,
            Expression<Real> secondOperand) {
        super(Real.Type, firstOperand, secondOperand);
    }
    
    @Override
    public Real evaluate() {
        return getFirstOperand().evaluate().subtract(
                getSecondOperand().evaluate());
    }
    
    @Override
    public Expression<Real> differentiate(Variable<Real> var)
            throws UnknownSuspensionException {
        return new SubtractionExpression(getFirstOperand().differentiate(var),
                getSecondOperand().differentiate(var));
    }
    
    @Override
    public SubtractionExpression newBinaryExpression(Expression<Real> firstExpr, Expression<Real> secondExpr) {
        return new SubtractionExpression(firstExpr, secondExpr);
    }
}
